//
//  UIView+PullView.m
//  类似淘宝详情页
//
//  Created by songhuipan on 16/6/26.
//  Copyright © 2016年 songhuipan. All rights reserved.
//

#import "UIView+PullView.h"
#import <objc/runtime.h>
#import "UIView+Frame.h"
#define kScreenWidth [UIScreen mainScreen].bounds.size.width
#define kScreenHeight [UIScreen mainScreen].bounds.size.height
@interface UIView  ()
@property (nonatomic,strong)UIView *maskView;
@property (nonatomic,strong)UIView *backView;
@end
@implementation UIView (PullView)

- (void)setMaskView:(UIView *)maskView {
    objc_setAssociatedObject(self, @"maskView", maskView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (UIView *)maskView {
    return objc_getAssociatedObject(self, @"maskView");
}
- (void)setMessageView:(UIView *)messageView {
    objc_setAssociatedObject(self, @"messageView", messageView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (UIView *)messageView {
    return objc_getAssociatedObject(self, @"messageView");
}
- (void)setBackView:(UIView *)backView {
    objc_setAssociatedObject(self, @"backView", backView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (UIView *)backView {
    return objc_getAssociatedObject(self, @"backView");
}
- (void)addpullView {
    if (!self.backView) {
        self.backView = [[UIView alloc]initWithFrame:self.bounds];
        if (!self.messageView) {
            self.messageView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.backView.w, self.backView.w*0.5)];
            self.messageView.backgroundColor = [UIColor blueColor];
        }
        if (!self.maskView) {
            self.maskView = [[UIView alloc]initWithFrame:self.backView.bounds];
            self.maskView.backgroundColor = [UIColor blackColor];
            self.maskView.alpha = 0.3;
        }
        [self.backView addSubview:self.maskView];
        [self.backView addSubview:self.messageView];
        [self addSubview:self.backView];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
        [self.maskView addGestureRecognizer:tap];
    }
    [UIView animateWithDuration:0.25 animations:^{
        self.backView.y = self.y;
    }];
}
- (void)tap:(UIGestureRecognizer *)recognizer {
    [UIView animateWithDuration:0.25 animations:^{
        self.backView.y = -self.backView.h;
    }];

}
@end





















